package com.etone.smartAudit.task;

import com.etone.smartAudit.service.PPushLogService;
import com.etone.smartAudit.service.PortalTaskService;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Log4j2
public class PortalTask {

    @Value("${audit.task.enable:false}")
    private Boolean enableTask;

    @Autowired
    private PPushLogService pPushLogService;


    @Autowired
    private PortalTaskService portalTaskService;

    /**
     * 每隔5分钟重试推送代办失败的数据
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void sygnFaiLog() {
        if (enableTask) {
            log.info("===========================开始重试推送代办失败的数据===========================");
            pPushLogService.sygnFaiLog();
            log.info("===========================结束推送代办失败的数据===========================");
        }

    }

    /**
     * 每晚凌晨2点同步组织数据1次
     */
    @SneakyThrows
    @Scheduled(cron = "15 2 * * * ?")
    public void synOrgAndEmployee() {
        if (enableTask) {
            log.info("===========================开始同步组织数据===========================");
            portalTaskService.synOrgAndEmployee();
            log.info("===========================同步组织数据完成===========================");
        }

    }

}
